package com.hddf.project.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.hddf.project.base.BaseDaoImpl;
import com.hddf.project.dao.FirstCategoryDao;
import com.hddf.project.pojos.FirstCategory;

public class FirstCategoryDaoImpl extends BaseDaoImpl implements FirstCategoryDao {

	/**
	 * 添加以及类别
	 * 
	 * @param fc
	 * @param s
	 */
	public void add(FirstCategory fc, Session s) throws Exception {
		super.add(fc, s);
	}

	/**
	 * 删除一级类别
	 * 
	 * @param first_category_id
	 * @param s
	 */
	public void delete(int first_category_id, Session s) throws Exception {
		super.deleteById(FirstCategory.class, first_category_id, s);
	}

	/**
	 * 删除一级类别
	 * 
	 * @param first_category_id
	 * @param s
	 */
	public void delete(FirstCategory fc, Session s) throws Exception {
		super.delete(fc, s);
	}

	/**
	 * 修改一级类别
	 * 
	 * @param fc
	 * @param s
	 */
	public void update(FirstCategory fc, Session s) throws Exception {
		super.update(fc, s);
	}

	/**
	 * 获取指定一级类别
	 * 
	 * @param first_category_id
	 * @param s
	 * @return
	 */
	public FirstCategory get(int first_category_id, Session s) throws Exception {
		return (FirstCategory) super.get(FirstCategory.class, first_category_id, s);
	}

	/**
	 * 根据名字获取一级类别
	 * 
	 * @param name
	 * @param s
	 * @return
	 */
	public FirstCategory getByName(String name, Session s) throws Exception {
		Query query = s.createQuery("from FirstCategory fc where fc.first_category_name=:temp ");
		query.setString("temp", name);
		FirstCategory fc = (FirstCategory) query.uniqueResult();
		return fc;
	}

	/**
	 * 获取全部一级类别
	 * 
	 * @param s
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<FirstCategory> getList(Session s) throws Exception {
		return super.find("from FirstCategory fc order by fc.sort asc", s);
	}

	/**
	 * 获取全部的一级分类ID
	 * 
	 * @param s
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<FirstCategory> getAllFirstCategoryId(Session s) {
		return super.find("select new FirstCategory(fc.first_category_id) from FirstCategory fc order by fc.sort asc",
				s);
	}
}
